package com.zbkj.crmeb.merchant.admin.controller;

import com.common.CommonPage;
import com.common.PageParamRequest;
import com.crmeb.core.common.CommonResult;
import com.zbkj.crmeb.store.request.ChannelFreeShippingActivityRequest;
import com.zbkj.crmeb.store.response.ChannelFreeShippingActivityResponse;
import com.zbkj.crmeb.store.service.ChannelFreeShippingActivityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("api/admin/mer/free/shipping/activity")
@Api(tags = "满额包邮")
public class MerChannelFreeShippingActivityController extends AdminBaseController{

    @Autowired
    private ChannelFreeShippingActivityService channelFreeShippingActivityService;

    /**
     * 功能描述: 保存或修改满额包邮活动
     * @Param: [request, servletRequest]
     * @Return: com.crmeb.core.common.CommonResult<java.lang.Boolean>
     * @Author: wangzh
     * @Date: 2022/12/30 14:59
     */
    @ApiOperation(value = "保存或修改")
    @PostMapping
    public CommonResult<Boolean> saveOrUpdate(@RequestBody ChannelFreeShippingActivityRequest request, HttpServletRequest servletRequest){
        return CommonResult.success(channelFreeShippingActivityService.saveOrUpdateActivity(request, getMerId(servletRequest)));
    }

    /**
     * 功能描述: 删除
     * @Param: [activityId]
     * @Return: com.crmeb.core.common.CommonResult<java.lang.Boolean>
     * @Author: wangzh
     * @Date: 2022/12/30 15:29
     */
    @ApiOperation(value = "删除")
    @DeleteMapping("/{activityId}")
    public CommonResult<Boolean> remove(@PathVariable Integer activityId){
        return CommonResult.success(channelFreeShippingActivityService.removeActivity(activityId));
    }

    /**
     * 功能描述: 获取分页列表/模糊查询
     * @Param: [name, request, servletRequest]
     * @Return: com.crmeb.core.common.CommonResult<com.common.CommonPage<com.zbkj.crmeb.store.response.ChannelFreeShippingActivityResponse>>
     * @Author: wangzh
     * @Date: 2022/12/30 16:29
     */
    @ApiOperation(value = "获取列表")
    @GetMapping
    public CommonResult<CommonPage<ChannelFreeShippingActivityResponse>> getList(@ApiParam("活动名称") String name, PageParamRequest request, HttpServletRequest servletRequest){
        return CommonResult.success(CommonPage.restPage(channelFreeShippingActivityService.getList(name, request, getMerId(servletRequest))));
    }

    /**
     * 功能描述: 获取活动详情
     * @Param: [activityId]
     * @Return: com.crmeb.core.common.CommonResult<com.zbkj.crmeb.store.response.ChannelFreeShippingActivityResponse>
     * @Author: wangzh
     * @Date: 2022/12/30 16:42
     */
    @ApiOperation(value = "获取详情")
    @GetMapping("/{activityId}")
    public CommonResult<ChannelFreeShippingActivityResponse> getInfo(@PathVariable Integer activityId){
        return CommonResult.success(channelFreeShippingActivityService.getInfo(activityId));
    }
}